package com.example.ythhome.busi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.ythhome.busi.entity.BusiCode;
import com.example.ythhome.busi.service.BusiCodeService;
import com.example.ythhome.busi.mapper.BusiCodeMapper;
import com.example.ythhome.system.entity.SysDict;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【t_busi_code(用于系统账号登录注册)】的数据库操作Service实现
* @createDate 2025-05-07 04:57:48
*/
@Service
public class BusiCodeServiceImpl extends ServiceImpl<BusiCodeMapper, BusiCode>
    implements BusiCodeService{

    @Autowired
    BusiCodeMapper busiCodeMapper;

    @Override
    public String getBusiCode(String busiType) {
        QueryWrapper<BusiCode> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("busi_type", busiType);
        BusiCode busiCode = busiCodeMapper.selectOne(queryWrapper);
        String bsCode = String.format(busiCode.getPrefix()+"%0" + busiCode.getLength() + "d", busiCode.getStart());
        busiCode.setStart(busiCode.getStart()+1);
        UpdateWrapper<BusiCode> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("busi_type", busiType);
        busiCodeMapper.update(busiCode,updateWrapper);
        return bsCode;
    }
}




